package com.stary.beetlsql.generator.config.querys;

import java.util.Map;

import com.stary.beetlsql.generator.config.IDbQuery;
import com.stary.beetlsql.generator.config.rules.DBType;
import com.stary.beetlsql.generator.util.StringUtils;

/**
 * <p>mysql查询</p>
 * @author stary {@link stary1993@qq.com}
 * @since 2019-8-6
 */
public class MysqlQuery implements IDbQuery {

	@Override
	public DBType dbType() {
		return DBType.MYSQL;
	}

	@Override
	public String tablesSql(String tableName) {
		String sql = " show table status ";
		if (!StringUtils.isEmpty(tableName)) {
			sql += " like '" + tableName + "' ";
		}
		return sql;
	}

	@Override
	public String tableFieldsSql(String tableName, String colName) {
		String sql = "show full fields from `" + tableName + "`";
		if (!StringUtils.isEmpty(colName)) {
			sql += " WHERE field = '" + colName + "' ";
		}
		return sql;
	}

	@Override
	public String tableName() {

		return "NAME";
	}

	@Override
	public String tableComment() {

		return "COMMENT";
	}

	@Override
	public String fieldName() {

		return "FIELD";
	}

	@Override
	public String fieldType() {

		return "TYPE";
	}

	@Override
	public String fieldComment() {

		return "COMMENT";
	}

	@Override
	public String fieldKey() {

		return "KEY";
	}

	@Override
	public boolean isKeyIdentity(Map<?,?> results) {		
		return "auto_increment".equals((String) results.get("Extra"));
	}


}
